import torch
import pandas as pd
from model import RecommenderModel
import config

class test_model():
    test_data = pd.read_csv("test.csv")

    # Assuming the test_data has appropriate columns for inputs and targets
    test_inputs = test_data[['userId', 'movieId']].values
    test_targets = test_data['rating'].values

    model = RecommenderModel(config.model_input_size, config.model_hidden_size, config.model_output_size)
    model.load_state_dict(torch.load('model.pth'))

    # Convert inputs and targets to tensors
    test_inputs_tensor = torch.Tensor(test_inputs)
    test_targets_tensor = torch.Tensor(test_targets)

    with torch.no_grad():
        outputs = model(test_inputs_tensor)

    # Calculate evaluation metrics
    # For example, Mean Squared Error (MSE) for regression problems
    criterion = torch.nn.MSELoss()
    test_loss = criterion(outputs.squeeze(), test_targets_tensor)
    print("Test Loss (MSE):", test_loss.item())

    # Other evaluation metrics like RMSE, MAE, etc. can also be calculated here
    # ...

    # You can return or print any other evaluation metrics as needed
